OB.Sys_EqStatistics_Alert = {
	index: 0,
	runGetMessages: function() {
		window.setTimeout(function() {
			OB.RemoteCallManager.call("com.basis.handler.MessageAlertStatisticsHandler", {}, {}, 
				function(response, data, request) {
					if (data.success && data.list.length > 0) {
						OB.Sys_EqStatistics_Alert.showMessage(data.list);
					} else {
						//OB.Sys_EqStatistics_Alert.runGetMessages();
					}
				}
			);
		}, 1000);//每1秒钟刷新一次消息提醒
	},
	showMessage: function(list) {
		this.msgList = list;
		this.index = 0;
		this.alertMessage(list);
	},
	alertMessage: function(list) {
			var msgArray = new Array();
			var tabArray = new Array();
			var tabTitle = '';
			var dataUpateDate = '';
			for(var ii=0;ii<list.size();ii++){
				dataUpateDate = list[ii].date;
				var msgContents = '<div>';
				var tempMsgInfo = isc.Label.create({
					align: "left",
					padding: 2,
					width: "100%",
					height: "30",
					contents: ""
				});
				
				switch(list[ii].msgType){
					case 'eqUseWarn':		msgContents+='<h3>设备使用提醒</h3>';tabTitle='设备使用';msgContents+='<p>　　设备数量：'+list[ii].allCount+'</p>';break;
					case 'eqLifeWarn':		msgContents+='<h3>设备寿命提醒</h3>';tabTitle='设备寿命';msgContents+='<p>　　设备数量：'+list[ii].allCount+'</p>';break;
					case 'eqMaintainWarn':	{
												msgContents+='<h3>设备维保超期任务</h3><p>　　超期数量：'+list[ii].expireCount+'</p>';
												msgContents+='<h3>设备维保预警任务</h3><p>　　预警数量：'+list[ii].warnCount+'</p>';
												msgContents+='<h3>设备维保任务总数</h3><p>　　总数数量：'+list[ii].allCount+'</p>';
												tabTitle='设备维保';
												break;}
					case 'eqRepairWarn':	{
												msgContents+='<h3>设备维修超期任务</h3><p>　　超期数量：'+list[ii].expireCount+'</p>';
												msgContents+='<h3>设备维修预警任务</h3><p>　　预警数量：'+list[ii].warnCount+'</p>';
												msgContents+='<h3>设备维修任务总数</h3><p>　　总数数量：'+list[ii].allCount+'</p>';
												tabTitle='设备维修';
												break;}
					case 'eqCheckWarn':		{	msgContents+='<h3>设备点检预警任务</h3><p>　　预警数量：'+list[ii].warnCount+'</p>';
												msgContents+='<h3>设备点检任务总数</h3><p>　　总数数量：'+list[ii].allCount+'</p>';
												tabTitle='设备点检';
												break;}
				}
				msgContents+='</div>';
				tempMsgInfo.setContents(msgContents);
				msgArray.push(tempMsgInfo);
				var openWindowId = list[ii].openWindowId;
				var menuName = list[ii].menuName;
				var recent = {openWindowId:openWindowId,menuName:menuName};
				//创建tab
				var testLabel1 = isc.Label.create({
					recent: recent,
					padding: 1,
					width: "100%",
					height: "135",
					align: "left",
					contents: msgContents,
					handleClick: function(){
						OB.Layout.ViewManager.openView(this.recent.openWindowId,{tabTitle:this.recent.menuName});
					}
				});
				var tempTabObj = {title:tabTitle, pane:testLabel1, ID:list[ii].msgType+"Tab", width:70};
				tabArray.push(tempTabObj);
			}
			this.dateInfo = isc.Label.create({
				padding: 5,
				width: "190",
				height: "18",
				contents: ""
			});
			this.dateInfo.setContents("更新时间：" + dataUpateDate);
			
			this.okButton = isc.OBFormButton.create({
				title : '确定',
				popup : this,
				action : function() {
					OB.Sys_EqStatistics_Alert.Msg_Alert_Window.closeClick();
					OB.Sys_EqStatistics_Alert.runGetMessages();
				}
			});
			
			//下方位置label
			var downTail = isc.HLayout.create({
				width: "100%",
				height: "22",
				align: "right",
				padding: 2,
				members: [
					this.dateInfo,
					this.okButton
				]
			});
			msgArray.push(downTail);
			
			/**/
			this.tabSet = isc.TabSet.create({
				ID : "tabSetWorkframe",
				width : "100%",
				height : "100%",
				canCloseTabs:false,
				canEditTabTitles:false,
				showMoreTab:true,
				tabBarAlign:'left',
				tabs :tabArray,
				tabSelected : function(tabNum, tabPane, ID, tab){
					
				}});
			
			
			this.Msg_Alert_Window = isc.Window.create({
				id: "Msg_Warn_Stastics_Window",
				width: 380,
				height: 305,
				title: '消息提醒',
				left: document.body.clientWidth - 382,
				top: document.body.clientHeight - 302,
				canDragResize: false,
				canDragReposition: true,
				showCloseButton: true,
				showMinimizeButton: false,
				items: [
				        this.tabSet,
				        downTail
				]
			});
		this.Msg_Alert_Window.setTitle("信息提示");
		this.okButton.show();
		this.Msg_Alert_Window.show();
	}
};

window.setTimeout(function() {
	OB.Sys_EqStatistics_Alert.runGetMessages();
}, 1000);

function alertObject(obj, filter) {
	var array = [];
	for (var key in obj) {
		if (filter) {
			if (key.indexOf(filter) == -1) {
				continue;
			}
		}
		array.push(key + ": " + obj[key]);
	}
	alert(array.join(", \n"));
}

Date.prototype.toString = function(bool) {
	var str = this.getFullYear() + "-" + 
		(this.getMonth() > 8 ? this.getMonth() + 1 : "0" + (this.getMonth() + 1)) + "-" + 
		(this.getDate() > 9 ? this.getDate() : "0" + (this.getDate()));
	if (bool) {
		str += (" " + (this.getHour() > 9 ? this.getHour() : "0" + (this.getHour())) + 
				":" + (this.getMinute() > 9 ? this.getMinute() : "0" + (this.getMinute())) + ":00");
	}
	return str;
}
